package cn.uniquesoft.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 验证工具类
 */

public class ValidateUtil {
    //验证邮箱格式是否正确
    public static boolean isEmail(String strEmail) {
        String strPattern = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
        Pattern p = Pattern.compile(strPattern);
        Matcher m = p.matcher(strEmail);
        if (m.matches()) {
            return true;
        } else {
            return false;
        }
    }
    //验证手机号 验证13，14，15，17，18,19开头号段
    public static boolean isCellphone(String str) {
        Pattern pattern = Pattern.compile("1[3|4|5|7|8|9][0-9]{9}");
        Matcher matcher = pattern.matcher(str);
        if (matcher.matches()) {
            return true;
        } else {
            return false;
        }
    }

    //验证是手机还是邮箱
    public static int isEamilOrCellphone(String name){
        int itype = 0;//邮箱or手机帐号标记
        if (ValidateUtil.isEmail(name)){//邮箱
            itype = 0;
        }
        if (ValidateUtil.isCellphone(name)){//手机号
            itype = 1;
        }
        return itype;
    }

}
